package com.example.stream.demostream.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zhe.log.annotation.Log;
import com.zhe.mybatis.annotations.DataPermissionAble;
import com.zhe.mybatis.enums.DataPermissionQuery;
import com.zhe.web.common.ApiResponse;
import com.zhe.web.common.ListResponse;
import com.zhe.web.common.PageResponse;
import com.zhe.web.common.Pagination;
import com.zhe.web.common.vo.PageVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.validation.annotation.Validated;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.example.stream.demostream.entity.SysManager;
import com.example.stream.demostream.service.SysManagerService;

import java.util.Collection;
import java.util.List;

/**
 * <p>
 * 平台管理人员表 前端控制器
 * </p>
 *
 * @author chenxiaohua
 * @since 2021-09-30
 */
@RestController
@RequestMapping("/sysManager")
@Api(value = "平台管理人员表 前端控制器",tags = "平台管理人员表 SysManager")
public class SysManagerController {

    @Autowired
    private SysManagerService sysManagerService;

    @ApiOperation(value = "保存或修改", notes = "保存或修改")
    @PostMapping("/saveOrUpdate")
    public ApiResponse<Boolean> saveOrUpdate(@RequestBody @Validated SysManager entity) {
        boolean result = sysManagerService.saveOrUpdate(entity);
        return ApiResponse.success(result);
    }

    @ApiOperation(value = "保存", notes = "保存")
    @PostMapping("/save")
    public ApiResponse<Boolean> save(@RequestBody @Validated SysManager entity) {
        boolean result = sysManagerService.save(entity);
        return ApiResponse.success(result);
    }

    @ApiOperation(value = "修改", notes = "修改")
    @PostMapping("/update")
    public ApiResponse<Boolean> update(@RequestBody @Validated SysManager entity) {
        boolean result = sysManagerService.updateById(entity);
        return ApiResponse.success(result);
    }

    @ApiOperation(value = "根据ID逻辑删除", notes = "根据ID逻辑删除")
    @PostMapping("/remove/{id}")
    public ApiResponse<Boolean> removeById(@PathVariable Long id) {
        boolean result = sysManagerService.removeById(id);
        return ApiResponse.success(result);
    }

    @ApiOperation(value = "根据多个ID批量逻辑删除", notes = "根据多个ID批量逻辑删除")
    @PostMapping("/batchRemoveById")
    public ApiResponse<Boolean> batchRemoveById(@RequestBody Collection<Long> ids) {
        boolean result = sysManagerService.removeByIds(ids);
        return ApiResponse.success(result);
    }

    @ApiOperation(value = "根据ID查询", notes = "根据ID查询")
    @GetMapping("/get/{id}")
    public ApiResponse<SysManager> getById(@PathVariable Long id) {
        SysManager result =  sysManagerService.getOne(new LambdaQueryWrapper<SysManager>().select(SysManager.class,bean->true).eq(SysManager::getId,id));
//        SysManager result = sysManagerService.getById(id);
        return ApiResponse.success(result);
    }

    @RequiresRoles("admin")
    @Log("列表查询")
    @ApiOperation(value = "列表查询", notes = "列表查询")
    @PostMapping("/list")
    public ListResponse<SysManager> list() {
        List<SysManager> list = sysManagerService.list();
        return ListResponse.success(list);
    }

    @ApiOperation(value = "自定义列表查询", notes = "自定义列表查询")
    @PostMapping("/listCustom")
    @DataPermissionAble(actionCodes = "page",queryType = DataPermissionQuery.ORG,column = "sm.org_code")
    public ListResponse<SysManager> listCustom() {
        List<SysManager> list = sysManagerService.listCustom();
        return ListResponse.success(list);
    }

    @ApiOperation(value = "分页查询", notes = "分页查询")
    @PostMapping("/page")
    public PageResponse<SysManager> page(@RequestBody @Validated PageVo vo) {
        return PageResponse.success(null);
    }
}



